﻿using System.Collections.ObjectModel;
using Seems.Model;

namespace Seems.SL.VM
{
	public class ViewModelLocator
	{
		private static ShellVM shell;

		public ViewModelLocator()
		{
			CreateShell();
		}

		/// <summary>
		/// Gets the Main property.
		/// </summary>
		public static ShellVM ShellStatic
		{
			get
			{
				if (shell == null)
				{
					CreateShell();
				}

				return shell;
			}
		}

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This non-static member is needed for data binding purposes.")]
		public ShellVM Shell
		{
			get
			{
				return ShellStatic;
			}
		}

		private readonly DiagramVM likeDiagram = new DiagramVM(diagramModel);
		private static readonly Diagram diagramModel = new Diagram();

		private readonly ElementShownOnDiagramVM likeElement =
			new ElementShownOnDiagramVM(
				new DiagramElement {
					Element = new Element
					{
						Name = "Element", 
						Attributes = new[]
							{
								new Attribute{ Name = "Attribute1"}, 
								new Attribute{ Name = "Attr2"}, 
								new Attribute{ Name = "A3"}
							}
					}});

		public DiagramVM LikeDiagram
		{
			get { return likeDiagram; }
		}

		public ElementShownOnDiagramVM LikeElement
		{
			get { return likeElement; }
		}


		/// <summary>
		/// Provides a deterministic way to delete the Main property.
		/// </summary>
		public static void ClearShell()
		{
//			shell.Dispose();
			shell = null;
		}

		/// <summary>
		/// Provides a deterministic way to create the Main property.
		/// </summary>
		public static void CreateShell()
		{
			if (shell == null)
			{
				shell = new ShellVM();
			}
		}

		/// <summary>
		/// Cleans up all the resources.
		/// </summary>
		public static void Dispose()
		{
			ClearShell();
		}
	}
}
